package com.naizhuai.ui.task.multtype;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.naizhuai.R;
import com.naizhuai.ui.components.CircleImageView;
import com.naizhuai.util.ViewUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.drakeet.multitype.ItemViewBinder;

/**
 * @author：lichenxi
 * @date 2018/5/9 15
 * email：525603977@qq.com
 * Fighting
 */
public class NameAndLeaderViewBinder extends ItemViewBinder<NameAndLeader, NameAndLeaderViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_name_and_leader, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull NameAndLeader nameAndLeader) {
        Context context=holder.itemView.getContext();
        holder.taskname.setText(String.format(context.getString(R.string.task_name_format),nameAndLeader.taskName));
        ViewUtils.showRoundImg(nameAndLeader.thumb,holder.leaderThumb);
        holder.leaderName.setText(nameAndLeader.leaderName);
    }

    @Override
    protected void onViewRecycled(@NonNull ViewHolder holder) {
        super.onViewRecycled(holder);
        Glide.with(holder.itemView.getContext()).pauseRequests();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.taskname)
        TextView taskname;
        @BindView(R.id.leader_thumb)
        CircleImageView leaderThumb;
        @BindView(R.id.leader_name)
        TextView leaderName;
        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
